package com.tjc.spring.core;

/**
 * @Author: tjc
 * @description
 * @Date Created in 23:36 2022-01-01
 */
public class BeanDefinitionValueResolver {

    BeanFactory beanFactory;

    public BeanDefinitionValueResolver(BeanFactory beanFactory) {
        this.beanFactory = beanFactory;
    }

    public Object resolveValueIfNecessary(Object originValue) {
        if (originValue instanceof TypedStringValue) {
            return ((TypedStringValue) originValue).getValue();
        } else if (originValue instanceof RuntimeBeanReference) {
            return beanFactory.getBean((String) ((RuntimeBeanReference) originValue).getValue());
        }
        throw new RuntimeException("unsopport valueHolder type.");
    }

}
